const http = require('http');
const urlTool = require('url');

//  GET   /books  显示  book
//  GET   /video  显示  video
const server = http.createServer((req, res) => {
  //测试 parse 方法, parse 用来解析 url, 返回一个对象
  // console.log(urlTool.parse(req.url, true).query.keyword);
  //获取请求的 url 的路径
  let {pathname, query} = urlTool.parse(req.url, true);//  req.url 
  //判断
  if(pathname === '/books'){
    res.end('books');
  }else if(pathname === '/video'){
    res.end(`video 您查询的关键字为 ${query.keyword}`)
  }else{
    res.end('404 Not Found');
  }
});

server.listen(8080, () => {
  console.log('server is running...');
});

